package com.drama.api.company.video.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.drama.api.base.*;
import com.drama.api.company.video.domain.vo.*;
import com.drama.api.company.video.service.ICompanyVideoService;
import com.drama.util.BindingResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.CompanyVideoController)
@RequestMapping(value = "/api/company/video")
@RestController
@SaCheckLogin
public class CompanyVideoController {

    @Autowired
    private ICompanyVideoService service;

    @ApiOperation(value = "查询视频列表")
    @GetMapping(value = "/list")
    public R<RestPage<List<CompanyVideoVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute CompanyVideoSearchVO searchVO) {
        List<CompanyVideoVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation(value = "添加视频信息")
    @PostMapping(value = "/add")
    public R create(@ApiParam(value = "添加参数") @Valid @RequestBody CompanyVideoAddVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.add(vo);
        }
        return result;
    }


    @ApiOperation(value = "检查名字是否重复【第一次】")
    @GetMapping(value = "/check_name")
    public R check_name( @ApiParam(value = "视频名称") @RequestParam String name) {
      service.checkName(name);
        return new R();
    }

    @ApiOperation(value = "更新视频信息")
    @PostMapping(value = "/update")
    public R create(@ApiParam(value = "添加参数") @Valid @RequestBody CompanyVideoUpdateVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.update(vo);
        }
        return result;
    }

    @ApiOperation(value = "删除视频信息")
    @PostMapping(value = "/delete")
    public R delete( @ApiParam(value = "修改参数") @Valid @RequestBody IDEntity delete) {
        service.delete(delete.getId());
        return new R();
    }


    @ApiOperation(value = "发起智能审核")
    @PostMapping(value = "/start_examine")
    public R start_examine( @ApiParam(value = "视频名称") @RequestBody IDsEntity ids) {
        if(ids.getIds()!=null&&ids.getIds().size()>0){
            for (String id:ids.getIds()){
                service.start_examine(id);
            }
        }
        return new R();
    }

    @ApiOperation(value = "发起智能标签读取")
    @PostMapping(value = "/start_label")
    public R start_label( @ApiParam(value = "视频名称") @RequestBody IDsEntity ids){
        if(ids.getIds()!=null&&ids.getIds().size()>0){
            for (String id:ids.getIds()){
                service.start_label(id);
            }
        }
        return new R();
    }

    @ApiOperation(value = "视频裁剪")
    @PostMapping(value = "/start_cropping")
    public R start_cropping( @ApiParam(value = "视频名称") @RequestBody VideoCropping videoCropping) {
        service.start_cropping(videoCropping);
        return new R();
    }

    @ApiOperation(value = "发起同步下发")
    @PostMapping(value = "/synchronous")
    public R synchronous( @ApiParam(value = "视频名称") @RequestBody IDsEntity ids) {
        if(ids.getIds()!=null&&ids.getIds().size()>0){
            for (String id:ids.getIds()){
                service.synchronous(id);
            }
        }
        return new R();
    }

}
